package data;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public abstract class SocketLoader implements ILoader{
	public SocketLoader(String host, int port) throws UnknownHostException, IOException {
		mSocket = new Socket(host, port);
		mReader = new BufferedReader(new InputStreamReader(mSocket.getInputStream()));
		mWriter = new BufferedWriter(new OutputStreamWriter(mSocket.getOutputStream(), ENCODING));
	}
	
	public InputStream x() throws IOException {
		return mSocket.getInputStream();
	}
	
	public InputStream getInputStream() throws IOException {
		return mSocket.getInputStream();
	}
	
	public OutputStream getOutputStream() throws IOException {
		return mSocket.getOutputStream();
	}
	
	public String readLine() throws IOException {
		return mReader.readLine();
	}
	
	public void write(String msg) throws IOException {
		mWriter.write(msg);
		mWriter.flush();
	}
	
	public void close() throws IOException {
		mReader.close();
		mSocket.close();
	}
	
	private Socket mSocket;
	private BufferedReader mReader;
	private BufferedWriter mWriter;
	
	//const
	private static final String ENCODING = "UTF-8";
	
}
